home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Presentations / Presentations ’97 / Sessions ’97 / Multiplatform Code⁄Data Sharing / HelloBothWorlds / Libraries / resfile_macos.cpp < prev    next >
Encoding:
Text File  |  1997-06-26  |  793 b   |  35 lines  |  [TEXT/CWIE]

  1.  
  2. // mail <chelly@eden.com> or surf http://www.eden.com/~chelly for feedback
  3. // free source code - do whatever you like with it
  4.  
  5. // mac os resource file access
  6. #include "resfile_macos.h"
  7.  
  8. #include <Resources.h>
  9.  
  10. resfile_macos::resfile_macos( short ref ) : m_ref( ref ) { }
  11.  
  12. resfile_macos::~resfile_macos() { }
  13.  
  14. void* resfile_macos::get_resource( long type, int id )
  15. {
  16.     // get resource, but don't load data
  17.     short prev = CurResFile();
  18.     UseResFile( m_ref );
  19.     SetResLoad( false );
  20.     Handle h = GetResource( type, id );
  21.     SetResLoad( true );
  22.     UseResFile( prev );
  23.     
  24.     // not found
  25.     if ( !h ) return nil;
  26.     
  27.     // copy to memory block and return
  28.     long const size = GetResourceSizeOnDisk( h );
  29.     char* data = new char [size];
  30.     ReadPartialResource( h, 0, data, size );
  31.     ReleaseResource( h );
  32.     return data;
  33. }
  34.  
  35.